package com.tinem.platform.module.starter.sdk.config;

import com.tinem.platform.module.starter.sdk.MessageCode;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.StaticMessageSource;

import java.util.Locale;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className MessageAutoConfiguration
 * @description TODO
 * @site 
 * @company 
 * @create 2020-07-02 16:26
 */

@Configuration
public class MessageAutoConfiguration {
    @Bean
    @Primary
    public MessageSource messageSource(){
        Locale.setDefault(Locale.CHINESE);
        StaticMessageSource source = new StaticMessageSource();
        MessageCode.values().forEach(messageCode -> {
            messageCode.getLocalMessage().entrySet().stream().forEach(localMessageCode->{
                source.addMessage(messageCode.name(),localMessageCode.getKey(),localMessageCode.getValue());
            });
        });
        return source;
    }
}
